package com.zx.web.servelt;

import com.zx.bean.Order;
import com.zx.web.service.AdminOrderService;
import com.zx.web.service.impl.AdminOrderServiceImpl;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @author 章鑫
 * @version V1.0
 * @Project 2022-09-05
 * @Package com.zx.web.servelt
 * @Description:
 * @Date 2022/9/16 16:07
 */
@WebServlet("/adminorderservlet")
public class AdminOrderServlet extends BaseServlet{

    AdminOrderService adminOrderService = new AdminOrderServiceImpl();

    /**
     * 查看订单
     * @param req
     * @param resp
     * @return
     */
    public String getAllOrder(HttpServletRequest req, HttpServletResponse resp){

        List<Order> orderList = adminOrderService.getAllOrder();

        req.setAttribute("orderList",orderList);

        return "forward:/admin/showAllOrder.jsp";
    }

    /**
     * 发货
     * @param req
     * @param resp
     * @return
     */
    public String sendOrder(HttpServletRequest req, HttpServletResponse resp){

        String oid = req.getParameter("oid");
        adminOrderService.updateStatus(oid);

        return "redirect:/adminorderservlet?method=getAllOrder";
    }

    /**
     * 搜索order
     * @param req
     * @param resp
     * @return
     */
    public String searchOrder(HttpServletRequest req, HttpServletResponse resp){

        String username = req.getParameter("username");
        String status = req.getParameter("status");

        List<Order> orderList = adminOrderService.searchOrder(username,status);

        req.setAttribute("orderList",orderList);

        return "forward:/admin/showAllOrder.jsp";
    }
}
